home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: How to detect EOF?/filepointer problem.
- Date: 12 Apr 1996 11:35:11 -0700
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4km7ovINN7r@keats.ugrad.cs.ubc.ca>
- References: <316F8932.2BAF@www.partio.fi>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <316F8932.2BAF@www.partio.fi>,
- R.K.Brand <ralph@www.partio.fi> wrote:
- >Sorry to bother you, but I have a problem
- >while scanning through a file too see whether
- >or not a certain word occurs.
- >When I run out of file, fscanf() keeps
- >returning the last line, instead of some NULL
- >value I would find logical (but who am I?).
-
- How can fscanf() ``return a line'', when its return type is int?
-
- >How can I test for the end of the file?
-
- Not directly. fscanf() returns the number of fields it was able to retrieve.
- For example, if you use a conversion string "%s", it will return 1 if it was
- able to retrieve a whitespace-delimited string, or zero otherwise. I'd take the
- zero as a cue that there aren't any more words available in the input.
-
- >The second problem is how to manipulate a
- >pointer of type "FILE"..so, a filepointer.
- >At a certain point I want to skip 11 chars back
- >in the file and start writing.
-
- This is tricky in conjunction with a scanning function like fscanf(). You have
- to understand what it does with the whitespace after the word.
-
-
- >string-=11; gives me an error and after
- >string--; fprintf(string,"foo"); does not do
- >anything anymore.
-
- The FILE * is not a pointer to the characters of the file! You may not
- alter the value of this pointer!
-
- The FILE * pointer points to a structure which maintains a whole ton of
- information about an open stream. To advance or retreat the file pointer, you
- must use the fseek() function.
-
- >I you respond to this one, please do also mail
- >me a copy.
-
- Sigh.
- --
-
-